<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <title>国象选品后台</title>
    <link rel="stylesheet" href="../../layui/css/layui.css"/>
    <link rel="stylesheet" href="css/admin.css"/> 
   <style type="text/css">
    .layui-table-cell {
            height: auto;
            line-height: 38px;
            }
    </style>
</head>
<body>
	<div class="container">
	    <div class="content-search">
			<!-- <form class="layui-form layui-form-pane" action=""> -->
				<div class="layui-inline">
					<label class="layui-form-label">账号名称</label>
					<div class="layui-input-block">
						<input  autocomplete="off" id="channelUser_id"  placeholder="账号名称" class="layui-input" type="text"/>
					</div>
				</div>
				<div class="layui-inline"><button class="layui-btn" data-type="reload">查询</button></div>
		</div>
		<div class="tar mt10">
			<button class="layui-btn layui-btn-normal layui-btn-small add1">+添加账号</button> 
		</div>
		
		
		<div class="table-listm roll-x">
			<table id="channel_user_info_manager" lay-filter="channel_user_info_manager"></table>  
		</div>
	</div>
	<div id="table-pages" style="text-align:center"></div>
	<script type="text/javascript" src="../../layui/layui.js"></script>
    <script>
        var arrayObj = new Array(); ;　
    
		layui.use(['jquery', 'laydate','form','layer','laypage','table'], function(){
			var $ = layui.jquery,
			    laydate = layui.laydate,
			    layer = layui.layer,
			    table = layui.table,
			    laypage = layui.laypage;


		table.render({
			elem: '#channel_user_info_manager',
			height: 'full-50',
			id:'channel_user_table_id',
			url: '../../web/find_channelUsers',
			//page: true ,
			loading: true,
			text: {
				none: '暂无相关数据'
			},
			cellMinWidth: 80,
			cols: [
				[{type: 'numbers', title: '序号', width: '30'}
				,
				{
					field: 'level',
					width: '15%',
					title: '账户等级'
					//sort: true
				},
				{
					field: 'username',
					width: '15%',
					title: '账户名'
					//sort: true
				},
				{
					field: 'password',
					width: '10%',
					title: '密码'
					//sort: true
				}
				,
				{
					field: 'channel',
					width: '10%',
					title: '渠道名'
					//sort: true
				}
				,
				{
					field: 'status',
					width: '10%',
					title: '账户状态'
					//sort: true
				},
				{
					field: 'create_time',
					width: '15%',
					title: '创建时间',
					//sort: true
					templet:function (d) { 
					      //var newDate = new Date(d.createTime).toLocaleString();
					      return d.create_time
					 }
				},
				{
					width: '8%',
					title: '常用操作',
					//toolbar: "#userbar",
					templet:function (d) {
					      if(d.status=='正常'){ 
					          if(d.level=='管理员'){	 
					          		return '不可操作' 
					          }
					          else{ 
					           		return '<button class="layui-btn layui-btn-normal layui-btn-small a1" lay-event="del_user">冻结</button>'
					          }
					      }else if(d.status=='冻结'){
					          return '<button class="layui-btn layui-btn-normal layui-btn-small a1" lay-event="recover_user">解冻</button>'
					      }
					      
					 }
				}]
			],
			done:function(res){
			    
			},

			});
			
			
		   var active =
              {
                  reload: function () {
                      var channelUser = $('#channelUser_id').val();//获取输入框的值
                      if(channelUser ==''){
                             layer.msg("输入账户名称", {icon: 5,time:1000});return ;
                      }
                      //执行重载
                      table.reload('channel_user_table_id',
                          {
                                where: { channelUser: channelUser}//这里传参  向后台
		                        , url: '../../web/find_channelUsers_by_name'//后台做模糊搜索接口路径
		                        , method: 'post'
                        });
                  }
              };

 			//这个是用于创建点击事件的实例
            $('.content-search  .layui-btn').on('click', function ()
            {
                var type = $(this).data('type'); ////////////////   alert(type);   alert(active[type]);  alert(active[type].call(this));
                active[type] ? active[type].call(this) : '';
            });
            
            
			$(document).on("click", ".mt10 .add1", function() {
			   layer.open({
			      type:2
			      ,area:['30%', '55%']
			      ,title:"添加账户"
				  ,content: 'add_channelUser.html'
				});
				
				
			});
			
			
			//表格按钮监听
            table.on("tool(channel_user_info_manager)", function (e) {
                  var d = e.data;
                  if (e.event == "del_user") {
	                     id= d.id  ;
	                     layer.open({
							  content: '您确定冻结此 '+d.username+' 账户吗？'
							  ,btn: ['确定', '取消']
							  ,yes: function(index, layero){
								    	//按钮【按钮一】的回调
							            $.ajax({
							                    type : "POST",
							                    url : '../../web/del_channel_user',
							                    //async:true,
							                    data : {
							                        id:id
							                    },
							                    dataType : "json",
							                    success : function(data) {
							                             if(data.status==false){
							                            	 layer.msg(data.msg, {icon: 5,time:4000});
													     }else{
													         layer.msg(data.msg, {icon: 1,time:3000});
													         //执行重载
										                      table.reload('channel_user_table_id');
													     }
							                    }
							             });
							  }
							  ,btn2: function(index, layero){
							    //按钮【按钮二】的回调
							    layer.closeAll(index);
							    //return false 开启该代码可禁止点击该按钮关闭
							  }
							  ,cancel: function(){ 
							    //右上角关闭回调
							    //return false 开启该代码可禁止点击该按钮关闭
							  }
							});
                  }
            });

			//表格按钮监听
            table.on("tool(channel_user_info_manager)", function (e) {
                  var d = e.data;
                  if (e.event == "del_user") {
	                     id= d.id  ;
	                     layer.open({
							  content: '您确定冻结此 '+d.username+' 账户吗？'
							  ,btn: ['确定', '取消']
							  ,yes: function(index, layero){
								    	//按钮【按钮一】的回调
							            $.ajax({
							                    type : "POST",
							                    url : '../../web/del_channel_user',
							                    //async:true,
							                    data : {
							                        id:id
							                    },
							                    dataType : "json",
							                    success : function(data) {
							                             if(data.status==false){
							                            	 layer.msg(data.msg, {icon: 5,time:4000});
													     }else{
													         layer.msg(data.msg, {icon: 1,time:3000});
													         //执行重载
										                      table.reload('channel_user_table_id');
													     }
							                    }
							             });
							  }
							  ,btn2: function(index, layero){
							    //按钮【按钮二】的回调
							    layer.closeAll(index);
							    //return false 开启该代码可禁止点击该按钮关闭
							  }
							  ,cancel: function(){ 
							    //右上角关闭回调
							    //return false 开启该代码可禁止点击该按钮关闭
							  }
							});
                  }
                  else{
 	                     id= d.id  ;
	                     layer.open({
							  content: '您确定恢复此 '+d.username+' 账户吗？'
							  ,btn: ['确定', '取消']
							  ,yes: function(index, layero){
								    	//按钮【按钮一】的回调
							            $.ajax({
							                    type : "POST",
							                    url : '../../web/recover_channel_user',
							                    //async:true,
							                    data : {
							                        id:id
							                    },
							                    dataType : "json",
							                    success : function(data) {
							                             if(data.status==false){
							                            	 layer.msg(data.msg, {icon: 5,time:4000});
													     }else{
													         layer.msg(data.msg, {icon: 1,time:3000});
													         //执行重载
										                      table.reload('channel_user_table_id');
													     }
							                    }
							             });
							  }
							  ,btn2: function(index, layero){
							    //按钮【按钮二】的回调
							    layer.closeAll(index);
							    //return false 开启该代码可禁止点击该按钮关闭
							  }
							  ,cancel: function(){ 
							    //右上角关闭回调
							    //return false 开启该代码可禁止点击该按钮关闭
							  }
							});                 
                  
                  }
            });			
			
		});

	</script>

    
</body>

</html>
















